/**
 * @PROJECT 
 * @DATE 2018年7月21日 下午9:38:20
 * @AUTHOR LUYU
 */
package com.kool.evowkf.action.approve;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kool.core.base.IBaseAction;
import com.kool.core.exception.AppException;
import com.kool.evowkf.bean.io.approve.CMNODECIDXBean;
import com.kool.evowkf.bean.io.approve.CMWORKERINFOZBean;
import com.kool.evowkf.service.ApproveService;

/**
 * @DESCRIBE 查询结点工作组组员
 * @AUTHOR LUYU
 * @DATE 2018年7月21日 下午9:38:20
 *
 */
@Controller
public class QueryNodeWorkersAction implements IBaseAction {
	@Autowired
	private ApproveService service;

	@Override
	@ResponseBody
	@RequestMapping(value = "/comm/wkf/queryNodeWorkers", method = RequestMethod.POST)
	public JSONObject doAction(@RequestBody String sInput) throws AppException {
		JSONObject pkgIn = JSONObject.parseObject(sInput);
		JSONArray secIn = pkgIn.getJSONArray("CMNODECIDX");
		String nodeCid = null;
		if (secIn != null && secIn.size() > 0) {
			JSONObject propIn = secIn.getJSONObject(0);
			CMNODECIDXBean ioIn = JSON.toJavaObject(propIn, CMNODECIDXBean.class);
			nodeCid = ioIn.getNodeCid();
		}

		List<CMWORKERINFOZBean> list = service.queryNodeWorkers(nodeCid);

		JSONObject pkgOut = new JSONObject();
		JSONArray secOut = new JSONArray();
		for (CMWORKERINFOZBean ioOut : list) {
			JSONObject propOut = (JSONObject) JSON.toJSON(ioOut);
			secOut.add(propOut);
		}
		pkgOut.put("CMWORKERINFOZ", secOut);
		return pkgOut;
	}

}
